package com.ruoyi.process.controller;

import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.model.LoginBody;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.dto.LoginUserDto;
import com.ruoyi.framework.web.service.SysLoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Description:
 * @ProjectName: ruoyi
 * @Package: com.walker.process.controller
 * @ClassName: AppLoginController
 * @Author: yangyl
 * @CreateDate: 2022/4/23 21:39
 */
@RestController
public class AppLoginController {

    @Autowired
    private SysLoginService loginService;

    /**
     * 登录方法
     *
     * @param loginBody 登录信息
     * @return 结果
     */
    @PostMapping("/login")
    public AjaxResult login(@RequestBody LoginBody loginBody)
    {
        AjaxResult ajax = AjaxResult.success();
        // 生成令牌
        String token = loginService.login(loginBody.getUsername(), loginBody.getPassword());
        LoginUser loginUser = loginService.getUserInfoByToken(token);
        LoginUserDto userInfo=loginService.parseLoginUserDto(loginUser);
        ajax.put(Constants.TOKEN, token);
        ajax.put("userInfo", userInfo);
        return ajax;
    }


}
